<?php    
/*    
* 文件:code.php    
* 作用:验证码生成    
* 作者:PHP实战群:33918040 - 鱼尾唯一    
* 网址:http://bbs.ailf.cn/ http://www.fishwei.com/    
* 特注:由 没牙的草 指导 版权所有转载注明出处!有付出才会有收获!  
*/    
session_start();    
// 设置 content-type    
header("Content-type: image/png");   
$ChineseChar = array("人","出","来","友","学","孝","仁","义","礼","廉","忠","国","中","易","白","者","火","土","金","木","雷","风","龙","虎","天","地",   "生","晕","菜","鸟","田","三","百","钱","福 ","爱","情","兽","虫","鱼","九","网","新","度","哎","唉","啊","哦","仪","老","少","日","月 ","星"); 
// 创建图片    
$im = imagecreatetruecolor(120, 30);    

// 创建颜色    
$fontcolor = imagecolorallocate($im, 255, 255, 255);    
$bg = imagecolorallocate($im, 0, 0, 0);    

// 设置文字    
for($i=0;$i<4;$i++) $text .= $ChineseChar[array_rand($ChineseChar)];    

$_SESSION['code'] = $text; 
   
// 设置字体    
$font = 'simkai.ttf';    

// 添加文字    
imagettftext($im, 18, 0, 11, 21, $fontcolor, $font, $text);    

// 输出图片    
imagepng($im);    
imagedestroy($im);    
?>